package com.czy.owner.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.TextView;

import com.czy.owner.R;
import com.czy.owner.entity.CategoryModel;
import com.czy.owner.entity.ParityClassifyModel;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;


/**
 *  Created by wangyang on 2017/10/10.
 */

public class ClassifyRightAdapter  extends RecyclerArrayAdapter<ParityClassifyModel.NodesBeanX> {
    private static final int GROUP_TYPE = 0;
    private static final int CLASSIFY_TYPE = 1;


    public ClassifyRightAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == GROUP_TYPE) {
            return new HotShopClassifyHeaderHolder(parent);
        } else if (viewType == CLASSIFY_TYPE) {
            return new HotShopClassifyHolder(parent);
        }
        return null;
    }


    @Override
    public void OnBindViewHolder(BaseViewHolder holder, int position) {
        super.OnBindViewHolder(holder, position);
    }

    @Override
    public int getViewType(int position) {
        if (getItem(position).isGroup()) {
            return GROUP_TYPE;
        } else {
            return CLASSIFY_TYPE;
        }

    }

    public TipSpanSizeLookUp obtainTipSpanSizeLookUp() {
        return new TipSpanSizeLookUp();
    }

    public class TipSpanSizeLookUp extends RecyclerArrayAdapter.GridSpanSizeLookup {
        public TipSpanSizeLookUp() {
            super(2);
        }

        @Override
        public int getSpanSize(int position) {
            if (position < getHeaderCount() || position >= getCount() + getHeaderCount()) {
                return 2;
            } else {
                if (getItem(position).isGroup()) {
                    return 2;
                } else {
                    return 1;
                }
            }
        }
    }

    class HotShopClassifyHolder extends BaseViewHolder<ParityClassifyModel.NodesBeanX> {
        private TextView tvClassify;

        public HotShopClassifyHolder(ViewGroup parent) {
            super(parent, R.layout.item_right_classify);
            tvClassify = $(R.id.tv_classify_item);
        }

        @Override
        public void setData(ParityClassifyModel.NodesBeanX model) {
            super.setData(model);
            tvClassify.setText(model.getCategoryName());
        }
    }

    class HotShopClassifyHeaderHolder extends BaseViewHolder<ParityClassifyModel.NodesBeanX> {
        private TextView tvClassifyHeader;

        public HotShopClassifyHeaderHolder(ViewGroup parent) {
            super(parent, R.layout.item_right_classify_header);
            tvClassifyHeader = $(R.id.tv_classify_head_item);
        }

        @Override
        public void setData(ParityClassifyModel.NodesBeanX model) {
            super.setData(model);
            tvClassifyHeader.setText(model.getCategoryName());
        }
    }

}

